/***
 * @description 地址数据操作
 * @author zhang
 */

const Address = require('../../models/Address')

!(async () => {
   // 创建新地址
//    await Address.create({
//         username: '李四',
//         city: '成都',
//         department: 'xxxx小区',
//         houseNumber: '门牌号2',
//         name: 'lisi',
//         phone: '9999999'
//     })

    // 获取 地址列表
    // const userlist = await Address.find().sort({ updatedAt: -1 })

    // console.log(userlist)


    // 根据地址id 获取地址
    // const id = '60def92d9bd5b72090044105'
    // const lisiObj = await Address.findById(id)
    // console.log(lisiObj)

    // 更新地址数据
    const id = '60def92d9bd5b72090044105'
    const newData = {
        username: '李四',
        city: '四川',
        department: 'xxxx小区a',
        houseNumber: '门牌号2a',
        name: 'lisia',
        phone: '5555555555'
    }
    const lisiobj = await Address.findOneAndUpdate(
        { _id: id, username: '李四' },
        newData,
        { new: true }
    )
    console.log(lisiobj)
})()